package com.qipay.baas.mapper;

import com.qipay.baas.model.SpChannelRule;
import com.qipay.baas.model.SpChannelRuleExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface SpChannelRuleMapper {
    @SelectProvider(type=SpChannelRuleSqlProvider.class, method="countByExample")
    int countByExample(SpChannelRuleExample example);

    @Delete({
        "delete from `sp_channel_rule`",
        "where `id` = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into `sp_channel_rule` (`id`, `sp_id`, ",
        "`channel_type`, `max_total_amount`, ",
        "`current_total_amount`, `total_amount_last_time`, ",
        "`max_order_amount`, `min_order_amount`, ",
        "`min_time_stop`, `min_time_stop_duration`, ",
        "`update_time`)",
        "values (#{id,jdbcType=BIGINT}, #{spId,jdbcType=BIGINT}, ",
        "#{channelType,jdbcType=TINYINT}, #{maxTotalAmount,jdbcType=BIGINT}, ",
        "#{currentTotalAmount,jdbcType=BIGINT}, #{totalAmountLastTime,jdbcType=DATE}, ",
        "#{maxOrderAmount,jdbcType=BIGINT}, #{minOrderAmount,jdbcType=BIGINT}, ",
        "#{minTimeStop,jdbcType=TIME}, #{minTimeStopDuration,jdbcType=TIME}, ",
        "#{updateTime,jdbcType=TIMESTAMP})"
    })
    int insert(SpChannelRule record);

    @InsertProvider(type=SpChannelRuleSqlProvider.class, method="insertSelective")
    int insertSelective(SpChannelRule record);

    @SelectProvider(type=SpChannelRuleSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="sp_id", property="spId", jdbcType=JdbcType.BIGINT),
        @Result(column="channel_type", property="channelType", jdbcType=JdbcType.TINYINT),
        @Result(column="max_total_amount", property="maxTotalAmount", jdbcType=JdbcType.BIGINT),
        @Result(column="current_total_amount", property="currentTotalAmount", jdbcType=JdbcType.BIGINT),
        @Result(column="total_amount_last_time", property="totalAmountLastTime", jdbcType=JdbcType.DATE),
        @Result(column="max_order_amount", property="maxOrderAmount", jdbcType=JdbcType.BIGINT),
        @Result(column="min_order_amount", property="minOrderAmount", jdbcType=JdbcType.BIGINT),
        @Result(column="min_time_stop", property="minTimeStop", jdbcType=JdbcType.TIME),
        @Result(column="min_time_stop_duration", property="minTimeStopDuration", jdbcType=JdbcType.TIME),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<SpChannelRule> selectByExample(SpChannelRuleExample example);

    @Select({
        "select",
        "`id`, `sp_id`, `channel_type`, `max_total_amount`, `current_total_amount`, `total_amount_last_time`, ",
        "`max_order_amount`, `min_order_amount`, `min_time_stop`, `min_time_stop_duration`, ",
        "`update_time`",
        "from `sp_channel_rule`",
        "where `id` = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="sp_id", property="spId", jdbcType=JdbcType.BIGINT),
        @Result(column="channel_type", property="channelType", jdbcType=JdbcType.TINYINT),
        @Result(column="max_total_amount", property="maxTotalAmount", jdbcType=JdbcType.BIGINT),
        @Result(column="current_total_amount", property="currentTotalAmount", jdbcType=JdbcType.BIGINT),
        @Result(column="total_amount_last_time", property="totalAmountLastTime", jdbcType=JdbcType.DATE),
        @Result(column="max_order_amount", property="maxOrderAmount", jdbcType=JdbcType.BIGINT),
        @Result(column="min_order_amount", property="minOrderAmount", jdbcType=JdbcType.BIGINT),
        @Result(column="min_time_stop", property="minTimeStop", jdbcType=JdbcType.TIME),
        @Result(column="min_time_stop_duration", property="minTimeStopDuration", jdbcType=JdbcType.TIME),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    SpChannelRule selectByPrimaryKey(Long id);

    @UpdateProvider(type=SpChannelRuleSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SpChannelRule record);

    @Update({
        "update `sp_channel_rule`",
        "set `sp_id` = #{spId,jdbcType=BIGINT},",
          "`channel_type` = #{channelType,jdbcType=TINYINT},",
          "`max_total_amount` = #{maxTotalAmount,jdbcType=BIGINT},",
          "`current_total_amount` = #{currentTotalAmount,jdbcType=BIGINT},",
          "`total_amount_last_time` = #{totalAmountLastTime,jdbcType=DATE},",
          "`max_order_amount` = #{maxOrderAmount,jdbcType=BIGINT},",
          "`min_order_amount` = #{minOrderAmount,jdbcType=BIGINT},",
          "`min_time_stop` = #{minTimeStop,jdbcType=TIME},",
          "`min_time_stop_duration` = #{minTimeStopDuration,jdbcType=TIME},",
          "`update_time` = #{updateTime,jdbcType=TIMESTAMP}",
        "where `id` = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(SpChannelRule record);
}